Skip to content

Check exported buffers after the default callback returns - #735

Draft
AbhinavMir wants to merge 1 commit into
msgpack:mainfrom
AbhinavMir:packer-default-callback-exports
Draft

AbhinavMir wants to merge 1 commit into
msgpack:mainfrom
AbhinavMir:packer-default-callback-exports

Conversation

@AbhinavMir

@AbhinavMir AbhinavMir commented Aug 30, 2026 •

Copy link
Copy Markdown

The default callback can export the internal buffer with getbuffer().
The packer then continues and can reallocate that buffer.
The export points at freed memory after the reallocation.

Call _check_exports() after the callback returns. The packer now
raises BufferError. The pure Python packer already raises BufferError
in this case.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Other supported user-code hooks can still export the buffer before a reallocating write.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Prevents buffer invalidation after default exports the packer’s internal buffer.

Changes:

  • Checks active exports after default returns.
  • Adds regression coverage for the unsafe reallocation scenario.
File summaries
File Description
msgpack/_packer.pyx Adds post-callback export validation.
test/test_buffer.py Tests exported-buffer safety during callbacks.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread msgpack/_packer.pyx
Comment on lines +267 to +269
# The callback may have exported the internal buffer.
# Packing on would reallocate it and invalidate the export.
self._check_exports()

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants